<?php
namespace Admin\Controller;
use Admin\Controller\CommonController;

/**
 * 数据分析相关模块
 * @author wangdong
 */
class AnalysisController extends CommonController {
	/**
	 * 设备监控
	 */
	public function devcontrol(){
		if(IS_POST){
			$admin_db = D('Admin');
			$total = $admin_db->count();
			$order = $sort.' '.$order;
			$limit = ($page - 1) * $rows . "," . $rows;
			$list = $admin_db->table(C('DB_PREFIX').'admin A')->join(C('DB_PREFIX').'admin_role AR on AR.roleid = A.roleid')->field("A.userid,A.username,A.lastloginip,A.email,A.realname,AR.rolename,FROM_UNIXTIME(A.lastlogintime, '%Y-%m-%d %H:%i:%s') as lastlogintime")->order($order)->limit($limit)->select();
			$data = array('total'=>$total, 'rows'=>$list);
			$this->ajaxReturn($data);
		}else{
			$menu_db = D('Menu');
			$currentpos = $menu_db->currentPos(I('get.menuid'));  //栏目位置
			$datagrid = array(
		        'options'     => array(
    				'title'   => $currentpos,
    				'url'     => U('Admin/memberList', array('grid'=>'datagrid')),
    				'toolbar' => 'admin_memberlist_datagrid_toolbar',
    			),
		        'fields' => array(
		        	'用户名'      => array('field'=>'username','width'=>15,'sortable'=>true),
		        	'所属角色'    => array('field'=>'rolename','width'=>15,'sortable'=>true),
		        	'最后登录IP'  => array('field'=>'lastloginip','width'=>15,'sortable'=>true),
		        	'最后登录时间' => array('field'=>'lastlogintime','width'=>15,'sortable'=>true,'formatter'=>'adminMemberListTimeFormatter'),
		        	'E-mail'     => array('field'=>'email','width'=>25,'sortable'=>true),
		        	'真实姓名'    => array('field'=>'realname','width'=>15,'sortable'=>true),
		        	'管理操作'    => array('field'=>'userid','width'=>15,'formatter'=>'adminMemberListOperateFormatter'),
    			)
		    );
		    $this->assign('datagrid', $datagrid);
		    $this->display();
		}
	}
	
	/**
	 * 恢复出厂设置
	 */
	public function siteDefault(){
		if(IS_POST){
			$setting_db = D('Setting');
			if($setting_db->where('1')->count()){
				$state = $setting_db->where('1')->delete();
				if($state){
					$setting_db->clearCatche();
					$this->success('操作成功');
				}else{
					$this->error('操作失败');
				}
			}
			$this->success('操作成功');
		}
	}
}